<template>
  <el-dialog
    :title="dataForm.id ? $t('brand.revise') : $t('brand.add')"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      size="small"
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      :label-width="this.$i18n.t('language') === 'language' ? '170px' : '150px'"
    >

      <el-form-item label="适用类型" prop="type">
        <el-radio-group v-model="dataForm.type">
          <el-radio
            v-for="(type, index) in typeArray"
            :label="index"
            :key="index"
          >{{ type }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="dataForm.title"
          placeholder="输入举报标题"
          maxlength="20"
        ></el-input>
      </el-form-item>
      <el-form-item label="排序号" prop="orderNum">
        <el-input-number
          v-model="dataForm.orderNum"
          controls-position="right"
          :min="0"
          :label="$t('hotSearch.seq')"
          maxlength="100"
          size="small"
          show-word-limit>
        </el-input-number>
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <div class="default-btn" @click="visible = false">{{$t("coupon.cancel")}}</div>
      <div class="default-btn primary-btn" @click="dataFormSubmit()">{{$t("coupon.confirm")}}</div>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          type: 0,
          title: '',
          orderNum: 0
        },
        typeArray: ['原文', '评论/聊天']
      }
    },
    methods: {
      // 获取数据列表
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl('/admin/report/title/' + this.dataForm.id),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({ data }) => {
              this.dataForm = data
            })
          } else {
            this.$refs['dataForm'].resetFields()
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/admin/report/title`),
              method: this.dataForm.id != 0 ? 'put' : 'post',
              data: this.$http.adornData(this.dataForm)
            }).then(({ data }) => {
              this.$message({
                message: this.$i18n.t('publics.operation'),
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.$emit('refreshDataList', this.page)
                  this.visible = false
                }
              })
            }).catch((e) => {
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
